//
//  ZAQMainViewController.swift
//  ZAQWBDZT
//
//  Created by 赵安庆 on 16/9/19.
//  Copyright © 2016年 zaq. All rights reserved.
//

import UIKit
import SVProgressHUD
class ZAQMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let zaqTabBar = ZAQTabBar()

        zaqTabBar.zaqDelegate = self
        zaqTabBar.composeButtonClosure = {[weak self] in
            print("我是闭包过来的")
            if !ZAQUserAccountViewModel.sharedUserAccountViewModel.isLogin {
                SVProgressHUD.showError(withStatus: "请先登录, 亲~")
                return
            }

            if let target = self {
                //  代码执行到此表示已经登录
                let composeView = ZAQComposeView()
                composeView.show(target: target)

            }


        }

        setValue(zaqTabBar, forKey: "tabBar")

//添加姿势图控制器
        addChildViewController(childController: ZAQHomeTableViewController(), title: "首页", imageName: "tabbar_home")
         addChildViewController(childController: ZAQMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
         addChildViewController(childController: ZAQDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
         addChildViewController(childController: ZAQProfileTableViewController(), title: "我的", imageName: "tabbar_profile")

    }
//添加姿势图控制器方法的重载
    func addChildViewController( childController: UIViewController,title:String,imageName:String) {
        UITabBar.appearance().tintColor = UIColor.orange
        //设置tabBar图片
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        childController.tabBarItem.title = title
        childController.title = title

        //创建导航控制器
        let nav = ZAQNavigationViewController(rootViewController: childController)

        //添加姿势图控制器
        addChildViewController(nav)
    }

   }
extension ZAQMainViewController:ZAQTarBarDelegate{
    func  didSelectedComposeButton(){
        print("我是代理过来的")
    }
}

